package com.bjb.vr.common.utils;

import cn.hutool.cache.Cache;
import cn.hutool.cache.CacheUtil;
import com.bjb.vr.common.dto.ResDictionary;
import com.bjb.vr.common.dto.ResFavorites;
import com.google.common.cache.LoadingCache;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @desc: 缓存工具类
 * @author: HuJingBo
 * @time：2021年06⽉18⽇<br/>
 * @version：v1.0.0<br>
 */
@Slf4j
public class GuavaCacheUtil {

    private static LoadingCache<String, List<String>> tenantCache;
    private static LoadingCache<String, List<ResDictionary>> dictionaryCache;
    private static LoadingCache<String, ResDictionary> dictionaryCacheOne;
    private static LoadingCache<String, List<ResFavorites>> favoritesCache;
    private static Cache<String, String> lfuCache = CacheUtil.newLFUCache(1);

    /**
     * 获取信息设置
     */
    public static void setTenantCache(LoadingCache<String, List<String>> tenantCache) {
        GuavaCacheUtil.tenantCache = tenantCache;
    }

    /**
     * 获取信息获取
     */
    public static LoadingCache<String, List<String>> getTenantCache() {
        return GuavaCacheUtil.tenantCache;
    }

    /**
     * 字典信息（单条）--设置
     */
    public static void setDictionaryCacheOne(LoadingCache<String, ResDictionary> dictionaryCacheOne) {
        GuavaCacheUtil.dictionaryCacheOne = dictionaryCacheOne;
    }

    /**
     * 字典信息（单条）--获取
     */
    public static LoadingCache<String, ResDictionary> getDictionaryCacheOne() {
        return GuavaCacheUtil.dictionaryCacheOne;
    }

    /**
     * 字典信息（多条）--设置
     */
    public static void setDictionaryCache(LoadingCache<String, List<ResDictionary>> dictionaryCache) {
        GuavaCacheUtil.dictionaryCache = dictionaryCache;
    }

    /**
     * 字典信息（多条）--获取
     */
    public static LoadingCache<String, List<ResDictionary>> getDictionaryCache() {
        return GuavaCacheUtil.dictionaryCache;
    }

    /**
     * 我的收藏（多条）--设置
     */
    public static void setFavoritesCache(LoadingCache<String, List<ResFavorites>> favoritesCache) {
        GuavaCacheUtil.favoritesCache = favoritesCache;
    }

    /**
     * 我的收藏（多条）--获取
     */
    public static LoadingCache<String, List<ResFavorites>> getFavoritesCache() {
        return GuavaCacheUtil.favoritesCache;
    }

    /**
     * 有限容量缓存--设置
     */
    public static void setLfuCache(String key, String value) {
        lfuCache.put(key, value);
    }

    /**
     * 有限容量缓存--获取
     */
    public static String getLfuCache(String key) {
        return lfuCache.get(key);
    }
}
